let timeMap = {};
let id = 0; // 用来记录mySetInterval个数
function mySetInterval(callback, time) {
  let timerId = id;
  id++; // id 自增实现唯一id
  function fn() {
    callback();
    // 更新 timeMap[timeId] 里的值
    timeMap[timerId] = setTimeout(fn, time);
  }
  timeMap[timerId] = setTimeout(fn, time);
  return timerId;
}

function myClearInterval(id) {
  clearTimeout(timeMap[id]);
  delete timeMap[id];
}

// 测试
const timerId = mySetInterval(() => {
  console.log(new Date());
}, 1000)

setTimeout(() => { // 2秒后清除定时器
  myClearInterval(timerId)
}, 2000)
